#include "xmppcore/tlsstreamfeature.h"
#include "xmppcore/constants.h"

namespace yoohoo_xmppcore {

TlsStreamFeature::TlsStreamFeature() : StreamFeature(XMPP_START_TLS_NAME, XMPP_START_TLS_NAME) {
	required = false;
}

bool TlsStreamFeature::fromXml(QXmlStreamReader& reader) {
	reader.readNext();

	if (reader.hasError())
		return false;

	if (reader.isStartElement() && reader.prefix().toString() == "" &&
			reader.name().toString() == "required") {
		required = true;

		reader.readNext();
		if (!reader.isEndElement())
			return false;
	}

	if (required) {
		reader.readNext();

		if (reader.hasError())
			return false;
	}

	if (!reader.isEndElement())
		return false;

	return true;
}

bool TlsStreamFeature::isRequired() {
	return required;
}

}
